package Command;

/**
 * @author duanzhizhou
 * @date 2024/11/4
 */
public class Calculator {

    private double total;
    
    public void calc(char ch, double num) {
        switch (ch) {
            case '+':
                total += num;
                break;
            case '-':
                total -= num;
                break;
            case '*':
                total *= num;
                break;
            case '/':
                if (Double.compare(num, 0.0) == 0) {
                    throw new RuntimeException("除数不能为0");
                }
                total /= num;
                break;
            default:
                throw new RuntimeException("不支持的计算类型");
        }
        System.out.println(ch + " " + num + " =" + total);
    }
}
